package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.EcologyPoolPrize;
import com.sc.nft.enums.EcologyPoolLinkTypeEnum;
import com.sc.nft.enums.EcologyPoolPrizeBindTypeEnum;
import com.sc.nft.mapper.EcologyPoolPrizeMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author 刘国航
 * @since 2024/8/10 17:21
 */
@Slf4j
@Repository
public class EcologyPoolPrizeDao extends ServiceImpl<EcologyPoolPrizeMapper, EcologyPoolPrize> {

    public int deductionRedEnvelopes(Long id, BigDecimal receivePackNumber, Integer version) {
        return baseMapper.deductionRedEnvelopes(id, receivePackNumber, version);
    }

    public List<EcologyPoolPrize> listPrizeByIds(List<Long> ids, EcologyPoolPrizeBindTypeEnum ecologyPoolPrizeBindTypeEnum, EcologyPoolLinkTypeEnum ecologyPoolLinkTypeEnum) {
        if (CollectionUtils.isEmpty(ids) || Objects.isNull(ecologyPoolPrizeBindTypeEnum) || Objects.isNull(ecologyPoolLinkTypeEnum)) {
            return new ArrayList<>();
        }
        LambdaQueryWrapper<EcologyPoolPrize> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(EcologyPoolPrize::getBindId, ids);
        wrapper.eq(EcologyPoolPrize::getBindType, ecologyPoolPrizeBindTypeEnum);
        wrapper.eq(EcologyPoolPrize::getLinkType, ecologyPoolLinkTypeEnum);
        return list(wrapper);
    }

    public EcologyPoolPrize getPrizeById(Long id, EcologyPoolPrizeBindTypeEnum ecologyPoolPrizeBindTypeEnum, EcologyPoolLinkTypeEnum ecologyPoolLinkTypeEnum) {
        LambdaQueryWrapper<EcologyPoolPrize> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(EcologyPoolPrize::getBindId, id);
        wrapper.eq(EcologyPoolPrize::getBindType, ecologyPoolPrizeBindTypeEnum);
        wrapper.eq(EcologyPoolPrize::getLinkType, ecologyPoolLinkTypeEnum);
        return getOne(wrapper);
    }

    public List<EcologyPoolPrize> listPrizeById(Long id, EcologyPoolPrizeBindTypeEnum ecologyPoolPrizeBindTypeEnum, EcologyPoolLinkTypeEnum ecologyPoolLinkTypeEnum) {
        LambdaQueryWrapper<EcologyPoolPrize> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(EcologyPoolPrize::getBindId, id);
        wrapper.eq(EcologyPoolPrize::getBindType, ecologyPoolPrizeBindTypeEnum);
        wrapper.eq(Objects.nonNull(ecologyPoolLinkTypeEnum), EcologyPoolPrize::getLinkType, ecologyPoolLinkTypeEnum);
        return baseMapper.selectList(wrapper);
    }

    public List<EcologyPoolPrize> listPrizeById(List<Long> ids, EcologyPoolPrizeBindTypeEnum ecologyPoolPrizeBindTypeEnum, EcologyPoolLinkTypeEnum ecologyPoolLinkTypeEnum) {
        LambdaQueryWrapper<EcologyPoolPrize> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(EcologyPoolPrize::getBindId, ids);
        wrapper.eq(EcologyPoolPrize::getBindType, ecologyPoolPrizeBindTypeEnum);
        wrapper.eq(Objects.nonNull(ecologyPoolLinkTypeEnum), EcologyPoolPrize::getLinkType, ecologyPoolLinkTypeEnum);
        return baseMapper.selectList(wrapper);
    }

}
